<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="coinfaces">

        <title> Tag python on ../..</title>

    <link rel="stylesheet" href="../../theme/css/style.css">
    <link rel="stylesheet" href="../../theme/css/pygments.css">



</head>

<body>
    <div class="content">
<h1>python</h1>        <table class="posts">
            <tr><th>博文</th><th>分类</th><th>日期</th></tr>
<tr>
    <td class="post-title" title="如下面的代码所示：Python中定义实例方法时第一个参数是实例对象，而调用实例方法时则不需要传这个参数。因为从定义到调用，中间的某个步骤将实例对象和实例方法的第一个参数绑定了起来，这种绑定遵循哪些规则？本文试图通过一些试验来探讨这个问题。 class Foo(object): def spam(self, a): print(&#39;{}, {}&#39;.format(self.__class__.__name__, a)) foo = Foo() foo.spam(1) # Foo, 1 规则1、只能绑定类属性 Python中万物皆对象，类也不例外，在类的代码块中定义的变量和函数自动变成类对象的属性。既然只是属性，也可以直接通过属性赋值的形式定义，如下面的代码所示： class Foo(object): pass def spam(self, a): print(&#39;{}, {}&#39;.format(self.__class__.__name__, a)) foo …"><a href="../../posts/discover-python-bound-method/">探讨Python的绑定方法</a></td>
    <td class="post-meta"><a href="../../categories/tech/">tech</a></td>
    <td class="post-meta">2020-11-29</td>
</tr><tr>
    <td class="post-title" title="为不联网的Windows XP系统安装WinPython"><a href="../../posts/winpython-install/">WinPython安装笔记</a></td>
    <td class="post-meta"><a href="../../categories/tech/">tech</a></td>
    <td class="post-meta">2016-11-03</td>
</tr><tr>
    <td class="post-title" title="解释Python对象方法和函数的关系"><a href="../../posts/python-method/">Python对象方法</a></td>
    <td class="post-meta"><a href="../../categories/tech/">tech</a></td>
    <td class="post-meta">2016-10-19</td>
</tr><tr>
    <td class="post-title" title="用except语句捕捉多个（尤其是2个）异常时，别忘了加括号。"><a href="../../posts/python-misunderstandings-except-clause/">Python except语法误解</a></td>
    <td class="post-meta"><a href="../../categories/tech/">tech</a></td>
    <td class="post-meta">2016-10-14</td>
</tr><tr>
    <td class="post-title" title="学会正确使用strptime，避免引起歧义。"><a href="../../posts/python-misunderstandings-strptime/">strptime的误解</a></td>
    <td class="post-meta"><a href="../../categories/tech/">tech</a></td>
    <td class="post-meta">2016-10-13</td>
</tr><tr>
    <td class="post-title" title="Python进阶大局观。"><a href="../../posts/python-from-apprentice-to-guru/">Python从入门到精通</a></td>
    <td class="post-meta"><a href="../../categories/tech/">tech</a></td>
    <td class="post-meta">2016-09-13</td>
</tr>
        </table>

    <div class="pagination">
        <span class="pagination-left">
        </span>
        <span>
            Posts
                under python
        </span>
        &middot;
        <span>Page 1 / 1</span>
        <span class="pagination-right">
        </span>
    </div>
    </div>
<nav class="nav sidebar">
    <div class="siteinfo">
        <div class="sitename"><a href="../..">coinfaces</a></div>
        <div class="tagline">Another Side of Life</div>
    </div>

        <a href="../../tags/">tags</a>
        <a href="../..">&larr; Home</a>
</nav><footer class="footer">
    <span>
        &copy; jpli &middot;
        under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA 4.0</a>
    </span>
    |
    <span>
        Powered by:
        <a href="http://blog.getpelican.com/">Pelican</a>
    </span>
</footer></body>
</html>